package com.admin.service.declare;

import com.admin.common.context.DeclareContext;
import com.admin.common.enums.DeclareLogTypeEnum;
import com.admin.common.shiro.ShiroUtils;
import com.admin.domain.Declare;
import com.admin.domain.DeclareLog;
import com.admin.mapper.AdminMapper;
import com.admin.service.DeclareLogService;
import org.springframework.beans.factory.annotation.Autowired;

public abstract  class AbstractDeclareService implements BaseDeclareService{

    @Autowired
    private DeclareLogService logService;
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Declare declare(DeclareContext declareContext) {
        //申报信息保存
        Declare declare = saveDeclare(declareContext);
        //记录日志
        //saveLog(declare,declareContext);
        return declare;
    }

    protected abstract Declare saveDeclare(DeclareContext declareContext);


    private void saveLog(Declare declare,  DeclareContext declareContext) {
        DeclareLog declareLog = new DeclareLog();
        declareLog.setDeclareId(declare.getId());
        declareLog.setOperatorType(DeclareLogTypeEnum.TYPE_10.getKey());
        declareLog.setContent("新增申报至【"+ declareContext.getAdminDO().getAreaName()+"】");
        declareLog.setRemark("");
        declareLog.setUserLevel(declareContext.getAdminDO().getMemberLevel());
        StringBuffer levelName = new StringBuffer();
        levelName.append(declareContext.getAdminDO().getCountryName()).append("【").append(declareContext.getAdminDO().getVillageName()).append("】");
        declareLog.setUserLevelName(levelName.toString());
        declareLog.setOperatorName(ShiroUtils.getUserName());
        logService.insertLog(declareLog);
    }

}
